import { Injectable } from "@angular/core";
import { HttpClient, HttpParams } from "@angular/common/http";
import { Observable } from "rxjs";
@Injectable({
  providedIn: 'root'
})
export class LoginService {
  // 用户名登录
  public userUrl = "/sys/user/login";
  // 验证码登录
  public codeUrl = "/sys/user/confirmLogin";
  public mobileCodeUrl = '/sys/user/mobile';

  // 菜单列表
  public menuList_URL = "/sys/menu/menuQuery";

  constructor(public httpClient: HttpClient) { }

  /**
   * 用户名登录
   * @param json 
   * @returns 
   */
  public login(json: any | null) {
    return this.httpClient.post(this.userUrl, json).toPromise();
  }

  /**
   * 验证码登录
   * @param params 
   * @returns 
   */
  public codeLogin(params: any) {
    return this.httpClient.post(this.codeUrl, params).toPromise();
  }

  /**
   * 获取手机验证码
   * @param params 
   * @returns 
   */
  public getMobileCode(params: any) {
    return this.httpClient.post(this.mobileCodeUrl, params).toPromise();
  }

  /**
   * 查询菜单列表
   * @returns 
   */
  public menuList(): Observable<any> {
    return this.httpClient.post(this.menuList_URL, null);
  }
}
